//
//  SceneMgr.m
//  TestMenuSystem
//
//  Created by Ronald Ram on 12/21/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "SceneMgr.h"
#import "CCMenu.h"
#import "CCMenuItem.h"
#import "MainMenu.h"

//#import "Options.h"
//#import "NewGame.h"
//#import "Credits.h"



@implementation SceneMgr
static SceneMgr *instance = nil;

@synthesize current = current_;

//swap menu layers, instead of swapping scenes!!
- (void) switchLayer: (CCLayer *) layer withAction: (id) action
{
    CCLayer *tmp; BOOL canRemove = NO;
    
    if ( self.current != nil )
    {
        tmp = self.current; canRemove = YES;
    }
    
    for (id child in layer.children)
    {
        [child runAction: action];
    }
    
    self.current = layer;
    [self addChild: self.current];
    
    if ( canRemove ) [self removeChild: tmp cleanup:YES];
}


+ (SceneMgr *) scene
{
    @synchronized (self)
    {
        if ( instance == nil ) instance = [[SceneMgr alloc] init];
    }
    return instance;
}

- (id) init
{
    if (self = [super init] )
    {
        current_ = [MainMenu node];
        [self addChild: current_];
    }
    return self;
}

- (void) dealloc
{
    [self removeAllChildrenWithCleanup: YES];
    [super dealloc];
}


@end
